// pages/addcourse/addcourse.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tId:'',
        cId:'',
        cname:''
    },

    formSubmit(e) {
        console.log('form发生了fromSubmit事件，携带数据为：', e.detail.value)
        let{tId,cId,cname} = this.data;
        let postData = {
            tId:this.data.tId,
            cId:this.data.cId,
            cname: this.data.cname,
        }
        postData = {...this.data}
        postData = {tId,cId,cname}

        wx.request({
            url: 'http://localhost/public/course/course/addcourse',
            method: "POST",
            data: postData,
            success: ({data}) => {
                console.log(data);
                console.log(data.status);
                if(data.status === 'success'){
                    wx.switchTab({
                        url: '/pages/course/course',
                    })
                }else{
                    this.setData({message:data.message});
                }
            },
            fail:(err)=> {
                console.log(err);
            }
        })
    },
    formReset(e) {
        console.log('form发生了reset事件，携带数据为：', e.detail.value)
        this.setData({
          chosen: ''
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            tId:app.globalData.userId,
        })
    },

    
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})